<#macro chipTree filepath>
    <@tools.fileList path=filepath>
        <#list list as a>
            <li>
                <#local path=filepath+'/'+a.fileName>
            <#if a.directory>
                <a href="javascript:;" onclick="return false;">${a.fileName} </a>
                <ul>
                    <@chipTree path/>
                </ul>
            <#else>
                <@tools.metadata path=path>
                    <a href="javascript:;" onclick="use('${path}','${(object.alias)?has_content?then('<#-- '+object.alias+' -->','')?js_string}');$.pdialog.closeCurrent();return false;">
                        ${(object.alias)?has_content?then(object.alias+' ('+a.fileName+')',a.fileName)}
                    </a>
                </@tools.metadata>
            </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@tools.fileList>
</#macro>
<script>
function use(path,description){
    if('include'==$('input[name=use]:checked',$.pdialog.getCurrent()).val()){
        JUI.instances[$('textarea.code',navTab.getCurrentPanel()).data('id')].replaceSelection('${r'<@include path="'?no_esc}'+path+'${r'"/>'?no_esc}'+description);
    } else {
        JUI.instances[$('textarea.code',navTab.getCurrentPanel()).data('id')].replaceSelection('${r'<@import path="'?no_esc}'+path+'" namespace="'+$('input[name=namespace]',$.pdialog.getCurrent()).val()+'"${r'/>'?no_esc}'+description);
    }
}
</script>
<div class="pageFormContent" layoutH>
    <dl class="nowrap">
        <dt><@t.page 'use_way'/></dt>
        <dd>
            <label style="width:auto;">
                <input name="use" type="radio" value="include" checked="true"/>
                <@t.page 'include'/>
            </label>
            <label style="width:auto;">
                <input name="use" type="radio" value="import"/>
                <@t.page 'import'/>
            </label>
            <div class="hide"><label style="width:auto;"><@t.page 'name_space'/>:</label><input name="namespace" type="text" maxlength="10" size="10" value="t"/></div>
        </dd>
    </dl>
    <script>
    $('input[name=use]',$.pdialog.getCurrent()).on('change',function(){
        if('include'==$('input[name=use]:checked',$.pdialog.getCurrent()).val()){
            $('input[name=namespace]',$.pdialog.getCurrent()).parent().hide();
        } else {
            $('input[name=namespace]',$.pdialog.getCurrent()).parent().show();
        }
    });
    </script>
    <ul class="tree treeFolder">
<@chipTree ''/>
    </ul>
</div>
<div class="formBar">
    <ul>
        <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
    </ul>
</div>